package com.huabo.contract.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hbfk.util.PageInfo;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.mysql.entity.TblContractAppendixsigningMySql;
import com.huabo.contract.mysql.mapper.TblContractAppendixsigningMySqlMapper;
import com.huabo.contract.oracle.entity.TblContractAppendixsigning;
import com.huabo.contract.oracle.mapper.TblContractAppendixsigningMapper;
import com.huabo.contract.service.TblContractAppendixsigningService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class TblContractAppendixsigningServiceImpl implements TblContractAppendixsigningService {

    @Resource
    private TblContractAppendixsigningMapper contractAppendixsigningMapper;

    @Resource
    private TblContractAppendixsigningMySqlMapper tblContractAppendixsigningMySqlMapper;
    
    @Override
    public Map<String, Object> findFileListByContractIdPageInfo(Integer contractId, Integer pageNumber, Integer pageSize, TblContractAppendixsigning tca) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            PageInfo<TblContractAppendixsigning> pageInfo = new PageInfo<TblContractAppendixsigning>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            tca.setConstractId(new BigDecimal(contractId));
            pageInfo.setCondition(tca);
            pageInfo.setTlist(this.contractAppendixsigningMapper.findFileListByContractIdPageInfo(pageInfo));
            pageInfo.setTotalRecord(this.contractAppendixsigningMapper.findCountFileListByContractIdPageInfo(pageInfo));
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            PageInfo<TblContractAppendixsigning> pageInfo = new PageInfo<TblContractAppendixsigning>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            tca.setConstractId(new BigDecimal(contractId));
            pageInfo.setCondition(tca);
            pageInfo.setTlist(this.contractAppendixsigningMapper.findFileListByContractIdPageInfo(pageInfo));
            pageInfo.setTotalRecord(this.contractAppendixsigningMapper.findCountFileListByContractIdPageInfo(pageInfo));
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        }
    }

    @Override
    public TblContractAppendixsigning findInfoById(Integer singingId) {
    	if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
    		return this.contractAppendixsigningMapper.findBysingingId(singingId);
    	}else {
    		TblContractAppendixsigningMySql contract =  this.tblContractAppendixsigningMySqlMapper.findBysingingId(singingId);
    		TblContractAppendixsigning app  = new TblContractAppendixsigning(); 
    		app.setConstractId(contract.getConstractId());
    		return app;
    	}
    }
 
    
    @Override
    public void removeInfo(Integer singingId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.contractAppendixsigningMapper.deleteBySingingId(singingId);
        } else {
            this.contractAppendixsigningMapper.deleteBySingingId(singingId);
        }
    }

    @Override
    public Map<String, Object> saveEntity(TblContractAppendixsigning signing) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            this.contractAppendixsigningMapper.saveEntity(signing);
            resultMap.put("code", "1");
            resultMap.put("msg", "上传成功");
            resultMap.put("data", signing);
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            this.contractAppendixsigningMapper.saveEntity(signing);
            resultMap.put("code", "1");
            resultMap.put("msg", "上传成功");
            resultMap.put("data", signing);
            return resultMap;
        }
    }
}
